package com.hzjh.base.utils.other;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;
public class ScreenUtils {

    /**
     * 获取屏幕宽度
     */
    public static int getScreenWidth(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        return width;
    }

    public static int getScreenWidth2() {
        DisplayMetrics outMetrics = new DisplayMetrics();
        ActivityStackManage.currentActivity().getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);
        int widthPixel = outMetrics.widthPixels;
        return widthPixel;
    }


    /**
     * 获取屏幕高度
     */
    public static int getScreenHeight() {

        DisplayMetrics outMetrics = new DisplayMetrics();
        ActivityStackManage.currentActivity().getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);
//        int widthPixel = outMetrics.widthPixels;
        int heightPixel = outMetrics.heightPixels;

        return heightPixel;
    }


    /**
     * 是否使屏幕常亮
     *
     * @param activity 当前的页面的Activity
     */
    public static void keepScreenLongLight(Activity activity, boolean isOpenLight, boolean maxBrightness) {

        Window window = activity.getWindow();
        if (isOpenLight) {
            window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {
            window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }

        WindowManager.LayoutParams windowLayoutParams = window.getAttributes();
        windowLayoutParams.screenBrightness = maxBrightness ?
                WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL : WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
        window.setAttributes(windowLayoutParams);
    }

}
